<template>
  <div class="mainpg">
    <div class="main_spac1" style="padding-bottom: 5px">
      <div class="main_white padding10">
        <div class="main_crumbs boxdq">
          <div class="main_crumbs_l">
            <a href="javascript:;" @click="$router.back(-1)">
              <i class="el-icon-arrow-down"></i>返回
            </a>
            <em>|</em>
            <span>操作记录</span>
          </div>
        </div>
        <div class="mainor_form batch-wrap mg-t-14 form-item-mg">
          <el-form
            :inline="true"
            :model="form"
            class="demo-form-inline"
            ref="userListFrom"
            label-width="90px"
          >
            <el-form-item label="商品名称：" prop="name">
              <el-input
                v-model.trim="form.name"
                placeholder="商品名称"
                clearable
                class="wid220"
              ></el-input>
            </el-form-item>
            <el-form-item label="创建时间：" prop="role_id">
              <el-date-picker
                v-model="createTime"
                type="daterange"
                class="time220"
                :editable="false"
                unlink-panels
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                value-format="yyyy-MM-dd"
                :clearable="false"
                :picker-options="pickerOptions"
              />
            </el-form-item>
            <MainFormBtn @reset="reset" @getSearchFor="getArticleList" :loading="listLoading" :showBtn="false" />
          </el-form>
        </div>
        <div class="main_table" style="min-height: 620px">
          <el-table
            ref="multipleTable"
            v-loading="listLoading"
            :data="list.list.data"
            element-loading-text="加载中"
            fit
            highlight-current-row
          >
            <el-table-column label="商品名称" :show-overflow-tooltip="true">
              <template slot-scope="scope"
                >{{ scope.row.goods.name }} 【{{
                  scope.row.spu | spu
                }}】</template
              >
            </el-table-column>
            <el-table-column
              label="分组"
              prop="group_name"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              label="管理员"
              prop="user.name"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              label="操作内容"
              prop="type_name"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              label="值"
              prop="value"
              :show-overflow-tooltip="true"
            />
            <el-table-column
              label="创建时间"
              width="140"
              :show-overflow-tooltip="true"
            >
              <template slot-scope="scope">{{
                parseTime(scope.row.created_at, "{y}-{m}-{d} ")
              }}</template>
            </el-table-column>
          </el-table>
        </div>
        <div class="main_page boxdq">
          <div></div>
          <!-- 分页 -->
          <div class="main_page_r">
            <MainPagination
              :current-page="current.page"
              :page-sizes="[20, 30, 50, 100]"
              :page-size="limit"
              layout="total, sizes, prev, pager, next, jumper"
              :total="totalCount"
              background
              @size-change="changeLimit"
              @current-change="changePage"
            />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { offerlog_index } from "@/api/commodity/commodityGroup";
import { apiUrl, objKeySort, Md5 } from "@/utils/public";
import { parseTime } from "@/utils/index";
import dateOption from "@/options/dateOption";

export default {
  components: {},
  filters: {
    spu(data) {
      return data == null ? "/" : data.spu_name.title;
    },
  },
  data() {
    return {
      // 时间
      parseTime,
      // 新增
      addedFormVisible: false,
      // 搜索
      form: {
        name: "",
        start_time: "",
        end_time: "",
      },
      createTime: [],
      pickerOptions: dateOption,
      // 分页
      current: {
        page: 1,
        per_page: 20,
      },
      limit: 20,
      totalCount: 1,
      // 列表数据
      list: {
        list: {
          data: [],
        },
      },
      listLoading: false,
    };
  },
  methods: {
    reset() {
      this.$refs['userListFrom'].resetFields()
      this.createTime = []
      this.offerlog_index();
    },
    // 分页
    changeLimit(pageSize) {
      this.current.per_page = pageSize;
      this.offerlog_index();
    },
    changePage(page) {
      this.current.page = page;
      this.offerlog_index();
    },
    // 搜索
    getArticleList() {
      this.current.page = 1;
      this.offerlog_index();
    },
    // 列表
    offerlog_index() {
      this.listLoading = true;
      this.form.start_time = this.createTime[0] ? this.createTime[0] : "";
      this.form.end_time = this.createTime[1] ? this.createTime[1] : "";
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name, this.form, this.current)) +
              apiUrl().appsecret
          ),
        },
        apiUrl().name,
        this.form,
        this.current
      );
      offerlog_index(data).then((res) => {
        this.listLoading = false;
        if (res.errcode == 0) {
          this.list = res.data;
          this.totalCount = res.data.list.total;
        } else {
          this.$message.error(res.errmsg);
        }
      });
    },
  },
  created() {
    // 列表
    this.offerlog_index();
  },
};
</script>
<style lang="scss" scoped>
.mainor_form form {
  width: calc(100% - 120px);
}
</style>
